package com.example.user.myhjjf_app.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.user.myhjjf_app.HJJF_Url;
import com.example.user.myhjjf_app.R;
import com.example.user.myhjjf_app.model.Model_Content;
import com.example.user.myhjjf_app.model.Model_Regional;
import com.example.user.myhjjf_app.presenter.Implementation_operation;
import com.example.user.myhjjf_app.presenter.SiteOperation;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Activity_DkAdd extends AppCompatActivity {

    @BindView(R.id.btn_back)
    LinearLayout btnBack;
    @BindView(R.id.tx_title)
    TextView txTitle;
    @BindView(R.id.btn_edit)
    LinearLayout btnEdit;
    @BindView(R.id.et_dk_name)
    EditText etDkName;
    @BindView(R.id.et_dk_code)
    EditText etDkCode;
    @BindView(R.id.et_dk_ms)
    EditText etDkMs;
    @BindView(R.id.bt_add_dk)
    Button btAddDk;
    SiteOperation siteOperation;
    String type,id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity__dk_add);
        ButterKnife.bind(this);
        Bundle bundle = getIntent().getExtras();
        siteOperation = new Implementation_operation(this);
        id = bundle.getString("id");
        type = bundle.getString("type");
        if (!type.equals("add")){

            if (type.equals("select")) {

            }
        }else {
            txTitle.setText("添加端口");
        }
    }

    @OnClick({R.id.btn_back, R.id.btn_edit, R.id.bt_add_dk})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_edit:
                break;
            case R.id.bt_add_dk:
                siteOperation = new Implementation_operation(Activity_DkAdd.this);
                HashMap map = new HashMap();
                String url = HJJF_Url.getHJJF_Url().login("api/data/port_add.do");
                map.put("pkId", id);
                map.put("name", etDkName.getText().toString());
                map.put("port", etDkCode.getText().toString());
                map.put("description", etDkMs.getText().toString());
                Iterator iterator = map.entrySet().iterator();
                int i = 0;
                while (iterator.hasNext()){
                    Map.Entry entry = (Map.Entry) iterator.next();
                    if (entry.getValue().equals("")){
                        Toast.makeText(this, "所有选项不能为空~~", Toast.LENGTH_SHORT).show();
                        i=0;
                        break;
                    }else {
                        i=1;
                    }
                }
                if (i==1){
                    siteOperation.Add(map,url);
                }
                break;
        }
    }
}
